package com.ruoyi.project.system.course.service;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.project.system.course.mapper.CourseMapper;
import com.ruoyi.project.system.dept.mapper.DeptMapper;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.mapper.UserMapper;
import com.ruoyi.project.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.course.mapper.CourseArrangeMapper;
import com.ruoyi.project.system.course.domain.CourseArrange;
import com.ruoyi.project.system.course.service.ICourseArrangeService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 课程安排 服务层实现
 * 
 * @author Waynnn
 * @date 2019-04-02
 */
@Service
public class CourseArrangeServiceImpl implements ICourseArrangeService 
{
	@Autowired
	private CourseArrangeMapper courseArrangeMapper;

	@Autowired
	private CourseMapper courseMapper;

	@Autowired
	private DeptMapper deptMapper;

	@Autowired
	private UserMapper userMapper;
	/**
     * 查询课程安排信息
     * 
     * @param courseArrangeId 课程安排ID
     * @return 课程安排信息
     */
    @Override
	public CourseArrange selectCourseArrangeById(Long courseArrangeId)
	{
		CourseArrange courseArrange=courseArrangeMapper.selectCourseArrangeById(courseArrangeId);
		courseArrange.setDept(deptMapper.selectDeptById(courseArrange.getDeptId()));
		courseArrange.setCourse(courseMapper.selectCourseById(courseArrange.getCourseId()));
		courseArrange.setUser(userMapper.selectUserById(courseArrange.getTeacherId()));
	    return courseArrange;
	}
	
	/**
     * 查询课程安排列表
     * 
     * @param courseArrange 课程安排信息
     * @return 课程安排集合
     */
	@Override
	public List<CourseArrange> selectCourseArrangeList(CourseArrange courseArrange)
	{
		List<CourseArrange> courseArrangeList=courseArrangeMapper.selectCourseArrangeList(courseArrange);
		for (CourseArrange courseArrange1:courseArrangeList){
			courseArrange1.setDept(deptMapper.selectDeptById(courseArrange1.getDeptId()));
			courseArrange1.setCourse(courseMapper.selectCourseById(courseArrange1.getCourseId()));
			courseArrange1.setUser(userMapper.selectUserById(courseArrange1.getTeacherId()));
		}
	    return courseArrangeList;
	}
	
    /**
     * 新增课程安排
     * 
     * @param courseArrange 课程安排信息
     * @return 结果
     */
	@Override
	public int insertCourseArrange(CourseArrange courseArrange)
	{
	    return courseArrangeMapper.insertCourseArrange(courseArrange);
	}
	
	/**
     * 修改课程安排
     * 
     * @param courseArrange 课程安排信息
     * @return 结果
     */
	@Override
	public int updateCourseArrange(CourseArrange courseArrange)
	{
	    return courseArrangeMapper.updateCourseArrange(courseArrange);
	}

	/**
     * 删除课程安排对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteCourseArrangeByIds(String ids)
	{
		return courseArrangeMapper.deleteCourseArrangeByIds(Convert.toStrArray(ids));
	}
	
}
